package com.example.shopsystem.aop;

import com.example.shopsystem.control.Result;
import org.springframework.stereotype.Component;

import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * @author : [17151]
 * @version : [v1.0]
 * @description : [一句话描述该类的功能]
 * @createTime : [2022/4/4 12:24]
 * @updateUser : [17151]
 * @updateTime : [2022/4/4 12:24]
 * @updateRemark : [说明本次修改内容]
 */
@Component
public class WebUtil {
    public static void writeToResp(Object obj, HttpServletResponse response) {
        try {
            if (obj instanceof Result) {
                response.getWriter().println(obj);
                return;
            }
            if(obj instanceof String){
                response.getWriter().println(obj);
                return;
            }else if(obj instanceof Integer){
                response.getWriter().println(new Result<Integer>((Integer) obj,"",null));
                return;
            }
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}
